package com.woniuxy.special.exception;

import com.woniuxy.special.common.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(ManagerException.class)
    public Result handlerManagerException(ManagerException e) {
        e.printStackTrace();
        return Result.fail(e.getCode(), e.getMessage());
    }

    /**
     * 参数校验异常
     */
    @ExceptionHandler(ParameterValidException.class)
    public Result parameterValidException(ParameterValidException e) {
        e.printStackTrace();
        return Result.fail(e.getCode(), e.getMessage());
    }


    /**
     * 令牌校验异常
     */
    @ExceptionHandler(JwtException.class)
    public Result handlerJwtException(JwtException e) {
        e.printStackTrace();
        return Result.fail(e.getCode(), e.getMessage());
    }


    /**
     * 兜底操作，避免有异常没有被处理而直接返回给用户的情况出现
     *
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    public Result handlerException(Exception e) {
        e.printStackTrace();
        return Result.fail(500, e.getMessage());
    }

}
